package org.cuatrovientos.englishquizpello;



	import java.util.Scanner;
	import java.util.Vector;
/**
 * Represents a quiz with questions
 * @author dani
 *
 */
	public class Quiz {
		private Vector<Question> questions;
		private int correct;
		private String name;
		
		/**
		 * 
		 * @param name
		 */
		public Quiz (String name) {
			questions = new Vector<Question>();
			correct = 0;
			this.name = name;
			init();
		}
		
		/**
		 * inits vector with questions
		 */
		public void init () {
			questions.add(new Question("We study __ the university","in","on","at","into","at"));
			questions.add(new Question("We study __ the school","in","on","at","into","at"));
			questions.add(new Question("Tyrion is __ prison","in","on","at","into","in"));
			questions.add(new Question("Tyson was  __ jail","in","on","at","into","in"));
			questions.add(new Question("I was  __ the beach","in","on","at","into","on"));
			questions.add(new Question("Turn __ the left","in","on","at","into","on"));
			questions.add(new Question("I was waiting __ the corner","in","on","at","into","at"));
			questions.add(new Question("We met __ the theatre","in","on","at","into","at"));
			questions.add(new Question("It depends  __ the weather","in","on","at","off","in"));
			questions.add(new Question("We went  __ train","in","on","onto","by","by"));
		}
		
		/**
		 * adds question to questions Vector
		 * @param question
		 */
		public void addQuestion (Question question) {
			questions.add(question);
		}
		/**
		 * 
		 * @param qname
		 */
		public void delQuestion (String qname) {
			for (int i=0; i<questions.size();i++){
				if (questions.elementAt(i).getQuestname().equals(qname)){
					questions.removeElementAt(i);
			}
			}
		}
		
		/**
		 * 
		 * @return
		 */
		public int quizLength () {
			return questions.size();
		}
		
		public void makeQuiz () {
			Scanner reader = new Scanner(System.in);
			String line = "";
			int questionNumber = 1;
			
			for (Question question : questions) {
				showQuestion(questionNumber, question);
				line = reader.nextLine();
				showResult(line, question);
				questionNumber++;
			}
			// Change this to compare with the size of the Vector
			finalAssesment();
		}
/**
 * 
 */
		private void finalAssesment() {
			if (correct >=(questions.size()/2)) {
				System.out.println("Congratulations, you passed the exam with " + correct + " correct answers");
			} else {
				System.out.println("You failed: " + correct + ". Better luck next time");			
			}
		}
/**
 * 
 * @param line
 * @param question
 */
		private void showResult(String line, Question question) {
			if (line.toLowerCase().equals(question.getSolut())) {
				correct++;
				System.out.println("Ok, That was correct");
				System.out.println("Correct answers: " + correct + " out of " + 10);
			} else {
				System.out.println("Wrong answer. The correct was: ");
				System.out.println(question.getSolut());
				System.out.println("Correct answers: " + correct + " out of " + 10);
			}
		}
/**
 * 
 * @param questionNumber
 * @param question
 */
		private void showQuestion(int questionNumber, Question question) {
			System.out.println("Question " + questionNumber + ": " + question.getQuestname());
			System.out.println("Options ");
			System.out.println(question.getOp1());
			System.out.println(question.getOp2());
			System.out.println(question.getOp3());
			System.out.println(question.getOp4());
			System.out.print("Write the correct: ");
		}
	}

